package com.itheima.service.impl;
/*
    ヾ(❀ﾟ▽ﾟ)ノ 
 
 Grey1996year@163.com 
 
*/

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.OrderSettingMapper;
import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@Service(interfaceClass = OrderSettingService.class, protocol = "dubbo")
public class OrderSettingServiceImpl implements OrderSettingService {

	@Autowired
	private OrderSettingMapper orderSettingMapper;

	@Override
	public void add(List<OrderSetting> orderSettingList) {
		//遍历集合，取出OrderSetting
		for (OrderSetting orderSetting : orderSettingList) {
			//分别执行添加操作
			orderSettingMapper.add(orderSetting);
		}

	}

	@Override
	public List<Map> getOrderSetting(String date) {
		//2019-11
		String beginDate = date + "-" + 1;    //2019-11-1
		String endDate = date + "-" + 31;    //2019-11-31
		//
		Map<String, String> map = new HashMap<>();
		map.put("beginDate", beginDate);
		map.put("endDate", endDate);
		//将这个map作为查询数据库的参数传入
		List<OrderSetting> orderSettingList = orderSettingMapper.getOrderSetting(map);
		//遍历查询结果集合
		List<Map> list = new ArrayList<>();
		for (OrderSetting orderSetting : orderSettingList) {
			Map<String, Object> orderSettingMap = new HashMap<>();
			//
			Date orderDate = orderSetting.getOrderDate();
			int _date = orderDate.getDate();
			int settingNumber = orderSetting.getNumber();
			int reservations = orderSetting.getReservations();
			//
			orderSettingMap.put("date", _date);
			orderSettingMap.put("number", settingNumber);
			orderSettingMap.put("reservations", reservations);
			//添加进集合
			list.add(orderSettingMap);
		}
		return list;
	}

	/**
	 * 设置可预约人数
	 * @param orderSetting
	 */
	@Override
	public void setNumber(OrderSetting orderSetting) {
		//
		orderSettingMapper.setNumber(orderSetting);

	}
}
